package com.yiwei.zxp.activity;

import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentPagerAdapter;
import android.support.v4.view.ViewPager;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.yiwei.zxp.R;
import com.yiwei.zxp.api.Api;
import com.yiwei.zxp.base.BaseActivity;
import com.yiwei.zxp.fragment.BussinessOrderFragment;
import com.yiwei.zxp.fragment.KeyMapDailog;

import com.yiwei.zxp.fragment.MyCommentFragment;
import com.yiwei.zxp.util.Network;
import com.yiwei.zxp.util.RxLifeUtil;
import com.yiwei.zxp.util.ToastUtil;
import com.yiwei.zxp.view.HomeViewPager;
import com.yiwei.zxp.view.MyCommentTopLayout;
import com.yiwei.zxp.view.V19FrameLayout;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import butterknife.Unbinder;

/**
 * Created by xsooy-pc on 17-12-8.
 */

public class MyCommentActivity extends BaseActivity {


    @BindView(R.id.btn_back)
    ImageView btnBack;
    @BindView(R.id.txt_title)
    TextView txtTitle;
    @BindView(R.id.txt_right)
    TextView txtRight;
    @BindView(R.id.layout_title)
    V19FrameLayout layoutTitle;
    @BindView(R.id.layout_top)
    MyCommentTopLayout layoutTop;
    @BindView(R.id.pager)
    HomeViewPager pager;
    private Unbinder unbiner;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_my_comment);
        initBar();
        unbiner = ButterKnife.bind(this);
        init();
    }

    private void init() {
        txtTitle.setText("我的评价");
        Fragment[] fragments = new Fragment[5];
        for (int i = 0; i < 5; i++) {
            MyCommentFragment fragment = new MyCommentFragment();
            Bundle bundle = new Bundle();
            bundle.putString("keyword", i+"");
            fragment.setArguments(bundle);
            fragments[i] = fragment;
        }

        pager.setAdapter(new FragmentPagerAdapter(getSupportFragmentManager()) {

            @Override
            public Fragment getItem(int position) {
                return fragments[position];
            }

            @Override
            public int getCount() {
                return fragments.length;
            }
        });
        layoutTop.setOnChooseListener(new MyCommentTopLayout.OnChooseListener() {
            @Override
            public void onClick(int poi) {
                pager.setCurrentItem(poi);
            }
        });
    }

    public void get() {
        if (!Network.checkNetwork(this)) {
            ToastUtil.show(this, "网络连接失败");
            return;
        }

        loadingDialog.show();
        Api.api_service.getSetInvitecode().compose(RxLifeUtil.checkOn(this)).
                doFinally(() -> {
                    try {
                        loadingDialog.dismiss();
                    } catch (NullPointerException e) {

                    }
                }).
                subscribe(result -> {

                });
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        unbiner.unbind();
        unbiner = null;
    }




    @OnClick(R.id.btn_back)
    public void onViewClicked() {
        finish();
    }
}
